package threadTask;

/**
 * 说明:任务抽象类
 * Created on 2023/9/21 14:59
 *
 * @author yanghongjun <1737619387@qq.com>
 */
public abstract class ThreadTask implements Runnable {

    /**
     * 命令执行
     */
    protected abstract void action();

    @Override
    public void run() {
        try {
            action();
        } catch (Exception e) {
            System.out.println("执行失败");
        }
    }

    /**
     * 加入线程池
     */
    public void addToThreadPool() {
        ThreadPoolManager.getInstance().addTask(this);
    }

}
